﻿@{
    ViewBag.Title = "InspectionSettingForm";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    $(function () {
        InitialPage();
        GetTree1();
        GetGrid();
    });
    var _Type = "";
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
            }, 200);
            e.stopPropagation();
        });
    }

    function GetTree1() {
        var item = {
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson?EnCode=InspectionType",
            onnodeclick: function (item) {             
                _Type = item.value;
                $('#gridTable').jqGrid('setGridParam', {
                    postData: { Type: _Type },
                }).trigger('reloadGrid');
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Inspection/GetList",
            postData: { Type: _Type },
            datatype: "json",
            height: $(window).height() - 165.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Id", hidden: true },
                { label: "名称", name: "Name", index: "Name", width: 80, align: "left" },
                { label: "编码", name: "Code", index: "Code", width: 80, align: "left" },
                { label: "验收种类", name: "TypeName", index: "TypeName", width: 80, align: "left" },
                { label: "标准", name: "Criterion", index: "Criterion", width: 80, align: "left" },
                {
                    label: "责任部门", name: "ResponDepts", index: "ResponDepts", width: 100, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        return cellvalue != null ? top.clientdepartmentData[cellvalue] != undefined ? top.clientdepartmentData[cellvalue].FullName : "" : "";
                    }
                },
                { label: "创建时间", name: "CreateDate", index: "CreateDate", width: 80, align: "left" },
                { label: "创建人", name: "CreateUserName", index: "CreateUserName", width: 100, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
    }

   

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form1",
            title: '添加验收项',
            url: '/PropertyManage/CS_Inspection/Form',
            width: "450px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form1",
                title: '编辑验收项',
                url: '/PropertyManage/CS_Inspection/Form?keyValue=' + keyValue,
                width: "450px",
                height: "400px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }
    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_Inspection/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的角色！', 0);
        }
    }

</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">

    <div class="ui-layout-west">
        <div class="west-Panel" style="height:98%;">
            <div class="panel-Title">验收种类</div>
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">验收项目</div>
            <div class="titlePanel">
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-addAcceptance" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                        <a id="lr-editAcceptance" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-deleteAcceptance" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    @*<script>$('.toolbar').authorizeButton()</script>*@
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
